package com.hopu.oa.dao.notice;

import com.hopu.oa.entity.management.AoaStatusList;
import com.hopu.oa.entity.management.AoaTypeList;
import com.hopu.oa.entity.notice.AoaNoticeList;
import com.hopu.oa.entity.notice.AoaNoticeUserRelation;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface NoticeManageDao {

    List<AoaNoticeList> queryNoticeListById(@Param("id") int id, @Param("title") String title, @Param("index") int index, @Param("size") int size);

    @Select("select * from aoa_type_list where type_model='inform'")
    List<AoaTypeList> findTypeList();

    @Select("select * from aoa_status_list where status_model='inform'")
    List<AoaStatusList> findStatusList();

    @Select("select * from aoa_notice_list where notice_id=#{id}")
    AoaNoticeList queryNoticeList(int id);

    @Insert("insert into aoa_notice_list(content,is_top,modify_time,notice_time,status_id,title,type_id,url,user_id) values(#{content},#{isTop},#{modifyTime},#{noticeTime},#{statusId},#{title},#{typeId},#{url},#{userId})")
    @Options(useGeneratedKeys = true, keyProperty = "noticeId", keyColumn = "notice_id")
    int addNoticeList(AoaNoticeList noticeList);

    @Insert("insert into aoa_notice_user_relation (is_read,relatin_notice_id,relatin_user_id) values(#{isRead},#{relatinNoticeId},#{relatinUserId})")
    int addaddNoticeUser(AoaNoticeUserRelation noticeUserRelation);

    @Update("update aoa_notice_list set content=#{content},is_top=#{isTop},modify_time=#{modifyTime},notice_time=#{noticeTime},status_id=#{statusId},title=#{title},type_id=#{typeId},url=#{url},user_id=#{userId} where notice_id=#{noticeId}")
    int updateNoticeList(AoaNoticeList noticeList);

    @Delete("delete from aoa_notice_list where notice_id=#{id}")
    int deleteNoticeList(int id);

    @Delete("delete from aoa_notice_user_relation where relatin_notice_id=#{id}")
    int deleteNoticeUser(int id);

    //查询当前用户角色
    @Select("select role_id from aoa_user where user_id=#{userId} ")
    int queryRole(Integer userId);


    List<Integer> querySubordinate(int roleId, int deptId);

    @Insert("insert into aoa_notice_user_relation(is_read,relatin_notice_id,relatin_user_id) values(#{read},#{noticeId},#{userId})")
    int forwardInform(Integer read, Integer noticeId, Integer userId);

    @Select("select * from aoa_notice_user_relation where relatin_user_id=#{userId} and relatin_notice_id = #{noticeId} ")
    AoaNoticeUserRelation queryNoticeUserByUserIdAndNoticeId(Integer userId, Integer noticeId);

    @Update("update aoa_notice_user_relation set is_read = 1 where relatin_id = #{relatinId} ")
    int setRead(Integer relatinId);

}
